﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Publicuse.Entity.AttributeUtil.Validate
{
    /// <summary>
    ///取值范围验证
    /// </summary>
    public class IntValuesAttribute : BaseValidateAttribute
    {
        private int[] _Values = null;
        private string remark = null;
        public string GetRemark { get { return this.remark; } }

        public IntValuesAttribute(string remark,params int[] values)
        {
            this._Values = values;
            this.remark = remark;
        }

        public override bool Validate(object oValue)
        {
            if (oValue != null && !string.IsNullOrEmpty(oValue.ToString()))
            {
                return int.TryParse(oValue.ToString(), out int iValue)
               && this._Values != null
               && this._Values.Contains(iValue);
            }
            else
            {
                return true;
            }
        }
    }
}
